package tote.model;

import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.ForeignKey;

/**
 */
@Entity
//@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
@Table(name = "tMatch")
public class Match implements Serializable {
    private static final long serialVersionUID = -157177243640136793L;

    @Column(name = "matchid")
    private Integer matchid;

    @Column(name = "tourid")
    private Integer tourid;

    @Column(name = "matchdate")
    private Timestamp matchdate;

    private Team team1;

    @Column(name = "score1")
    private Integer score1;

    @Column(name = "score2")
    private Integer score2;

    private Team team2;

    @Column(name = "venue")
    private String venue;

    @Column(name = "matchurl")
    private String matchurl;

    @Id
    public Integer getMatchid() {
	return matchid;
    }

    public void setMatchid(Integer matchid) {
	this.matchid = matchid;
    }

    public Timestamp getMatchdate() {
	return matchdate;
    }

    public void setMatchdate(Timestamp matchdate) {
	this.matchdate = matchdate;
    }

    public Integer getScore1() {
	return score1;
    }

    public void setScore1(Integer score1) {
	this.score1 = score1;
    }

    public Integer getScore2() {
	return score2;
    }

    public void setScore2(Integer score2) {
	this.score2 = score2;
    }

    public String getVenue() {
	return venue;
    }

    public void setVenue(String venue) {
	this.venue = venue;
    }

    public String getMatchurl() {
	return matchurl;
    }

    public void setMatchurl(String matchurl) {
	this.matchurl = matchurl;
    }

    @Override
    public String toString() {
	return matchid + "{" + score1 + ":" + score2 + "}";
    }

    public void setTourid(Integer tourid) {
	this.tourid = tourid;
    }

    public Integer getTourid() {
	return tourid;
    }

    public void setTeam1(Team team1) {
	this.team1 = team1;
    }

    // @OneToOne(cascade = CascadeType.REFRESH)
    @ManyToOne
    // (cascade = CascadeType.ALL)
    @JoinColumn(name = "teamid1")
    @ForeignKey(name = "fk_tmatch_reference_tteam")
    // @ManyToOne
    // (cascade = CascadeType.ALL)
    public Team getTeam1() {
	return team1;
    }

    public void setTeam2(Team team2) {
	this.team2 = team2;
    }

    // @OneToOne(cascade = CascadeType.REFRESH)
    @ManyToOne
    @JoinColumn(name = "teamid2")
    @ForeignKey(name = "fk_tmatch_reference_tteam2")
    public Team getTeam2() {
	return team2;
    }
}
